﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FPC.Offer.Repository
{
    public class System_DictionaryTableRepository : BaseRepository<Model.System_DictionaryTable>, IRepository.ISystem_DictionaryTableRepository
    {
        /// <summary>
        /// 数据字典分组查询
        /// </summary>
        /// <param name="PlaceField"></param>
        /// <returns></returns>
        public dynamic SelectGroupBy()
        {
            var ss = DbContext.Set<Model.System_DictionaryTable>();
            var list = ss.GroupBy(p => new { p.PlaceField, p.PlaceTable, p.DictionaryName });
            var getlist = list.Select(g => new { g.Key.PlaceField, g.Key.DictionaryName, g.Key.PlaceTable, count = g.Count() });
            return getlist;
        }
        /// <summary>
        /// 根据表名获取表结构
        /// </summary>
        /// <param name="GetName"></param>
        /// <returns></returns>
        public dynamic GetTableStructure(string GetName)
        {
            var GetList = DbContext.Database.SqlQuery<string>("select name from syscolumns where id=object_id('" + GetName + "')");
            return GetList.ToList();
        }

        /// <summary>
        /// 根据获取数据库表名
        /// </summary>
        /// <param name="GetName"></param>
        /// <returns></returns>
        public dynamic GetDataBaseTable()
        {
            var GetList = DbContext.Database.SqlQuery<string>("SELECT Name FROM FPC_Offer..SysObjects Where XType='U' ORDER BY Name ");
            return GetList.ToList();
        }

    }
}
